
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta charset="utf-8">
  <title></title>
  <script>
      function submitForm() {
            var form = document.getElementById("myForm");
            var username = "messaging-client";
            var password = "secret";
            // 创建BASIC请求头的base64编码字符串
            var authHeader = 'Basic ' + btoa(username + ':' + password);
            // 设置请求头
            var xhr = new XMLHttpRequest();
            xhr.open(form.method, form.action, true);
            xhr.setRequestHeader('Authorization', authHeader);
            // 处理请求结果
            xhr.onreadystatechange = function () {
                if (xhr.readyState === XMLHttpRequest.DONE) {
                    if (xhr.status === 200) {
                        alert('请求成功');
                    } else {
                        alert('请求失败');
                    }
                }
            };
            // 发送请求
            xhr.send();
        }
  </script>
  </head>
  <body>
      客户端凭证认证模式：
      <form id="myForm" method="POST" action="http://localhost:8080/oauth2/token?grant_type=client_credentials">
        <input type="text" name="grant_type" value="client_credentials"> <br>
        <button type="button" onclick="submitForm()">提交</button>
    </form>
  </body>
</html>
